\documentclass{article}
\title{C\# Type converters, your friendly helpers!}
\author{jfang}
\begin{document}
\maketitle
\section{Introduction}
You may not have written yet your own type converter. But any time you developed a web form or windows form using the Visual Studio .NET designer or used the view state architecture of ASP.NET you have relied on the help of a type converter. As the name already states, type converters are used to convert from one type to another, for example an integer to a string. The .NET framework comes with a number of type converters which perform all that work for you for the most common .NET types. But when you create your own complex types then you need to create your own type converters. This article will explain how you can write your own type converter and then assign that to your own type.
\section{Where are type converters used?}
Type converters are mostly used to convert your type to a string or a string back to your type. Web controls and web forms have properties which you can view and edit through the property browser of the Visual Studio .NET designer. The property browser finds the type of the property and then the type converter associated with that type to convert the type to a string. Any changes the user makes to the property in the property browser is written back to the property, which again uses the type converter to convert from a string back to the type.\\
You can also design web forms through the Visual Studio .NET designer. This allows you to place new controls onto the web form and modify their properties. The designer creates the necessary form tags and properties. You can also switch to the \texttt{source mode} and then edit the tags itself. You can add new properties to a control or modify existing ones. This is called \texttt{declarative persistence}. The designer itself uses again type converters to convert a property from your type to a string and again from a string back to your type.\\
The state view framework provided by web controls and web forms also relies on type converters. Type converters provide a better performance then reflection. So whenever possibly avoid binary serialization which uses reflection. Provide your own type converter. You can not store complex types in state view unless it is marked serializable or has its own type converter associated.
\end{document}
